﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BinaryTree
{
    /// <summary>
    /// 层序(从左向右)
    /// </summary>
    class SequenceOrder
    {
        public static void LevelOrder(CreatTree.Tree tree)
        {
            if (tree == null) return;
            Queue<CreatTree.Tree> queue = new Queue<CreatTree.Tree>();
            queue.Enqueue(tree);
            while (queue.Any())
            {
                var item = queue.Dequeue();
                Console.Write(item.Value);
                if (item.Left != null)
                {
                    queue.Enqueue(item.Left);
                }
                if (item.Right != null)
                {
                    queue.Enqueue(item.Right);
                }
            }
        }
    }
}
